package dianmobile.eistarandroid.utils;

import android.text.TextUtils;

import com.android.volley.cookies.Cookie;

import java.util.Date;

/**
 * Created by admin on 15/7/6.
 */
public class DataCheck {
    public static void notNull(Object param) {
        if (param == null) {
            throw new NullPointerException();
        }
    }

    /**
     * 验证cookie的有效性
     *
     * @param url
     * @param cookie
     * @return
     */
    public static boolean checkCookie(String url, Cookie cookie) {
        String rex = "\\*" + cookie.getDomain() + "\\*";
        // 验证domain的有效性
        if (!TextUtils.isEmpty(cookie.getDomain())) {
            if (!url.matches(rex)) {
                return false;
            }
        }

        // 验证生命周期的有效性
        Date expires = cookie.getExpires();
        if (expires == null) {
            return true;
        }

        return expires.after(new Date());
    }
}
